<?php
defined('BASEPATH') OR exit('No direct script access allowed');
	class Auth extends CI_Controller {	
		public function login(){
			$this->load->helper(array('form', 'url'));	//加载辅助函数
	        $this->load->library('form_validation');	//加载表单验证类库
	        $this->form_validation->set_error_delimiters('<span class="help-block error">', '</span>');	//更改错误界定符
	        $this->form_validation->set_rules('username','用户名','required');	//设置验证规则
			$this->form_validation->set_rules('password', '密码', 'required|callback__auth_check');	//设置验证规则同时调用下面的auth_check()方法，回调验证函数
	        if ($this->form_validation->run() == FALSE){	//调用某组验证规则
	            $this->load->view('admin/login');
	        }else{
	        	$this->session->set_userdata('is_login', TRUE);	//set_userdata()方法添加session数据
	        	redirect("/admin/article/index");	            
	        }    
		}
		function _auth_check(){
			$username=$this->input->post('username');
			$password=md5($this->input->post('password'));
			$this->load->model('Admin_model');
	        if ($this->Admin_model->get_admin($username,$password)){
	            return TRUE;
	        }else{
	            $this->form_validation->set_message('_auth_check', '用户名或密码不正确');
	            return FALSE;
	        }
		}	
	}
?>